package com.wy.controller;

import com.wy.pojo.User;
import com.wy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @Author: wy
 * @Date:2019/10/29 16:17
 */
@RestController
@RequestMapping("/user")
@RefreshScope  //刷新配置
public class UserController {

    @Autowired
     private UserService userService;
      @GetMapping("/{id}")
    public User getUser(@PathVariable Long id){
         /* try {
              Thread.sleep(2000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }*/
          return    userService.findUser(id);
    }


     @GetMapping("/findAll")
     public List<User> findAll(){
           return   userService.findAll();
     }

      @GetMapping("/delete/{id}")
      public String delete(@PathVariable Long id){
            userService.delete(id);
          return "删除成功!";
      }

         @RequestMapping("/update")
       public String update(User user){
                userService.update(user);
                return  "修改成功!";
       }
}
